package com.hps.business.controller;

import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author heps
 * @date 2019/11/14 18:41
 */
@RestController
@RequestMapping("/user")
public class AuthController {

    @RequestMapping("/login")
    public Object login(String username, String password) {
        RestTemplate restTemplate = new RestTemplate();
        MultiValueMap<String, String> formParams = new LinkedMultiValueMap<>();
        formParams.set("username", username);
        formParams.set("password", password);
        formParams.set("grant_type", "password");
        formParams.set("scope", "server");
        formParams.set("client_id", "client_2");
        formParams.set("client_secret", "123456");
        return restTemplate.postForEntity("http://localhost:9098/oauth/token", formParams, OAuth2AccessToken.class).getBody();
    }
}
